package finance

import org.apache.commons.math.stat.StatUtils

class LoMacKinlayService {
    
    static transactional = true
    
    def evenItems(input) {
        def evenItems = []
        
        for( int i in (0..<input.size() ).step(2) ) 
            evenItems << input[i]
        
        return evenItems
    }
    
    def lnService
    
    double variance(input) {
        def deltas = lnService.deltaLn(input)
        return StatUtils.variance(deltas as double[])
    }
    
    def ratio(input) {
        def doubles = input as double[]
        def totalVariance = variance( doubles )
        def evenVariance = variance( evenItems(doubles) )
        
        return totalVariance / evenVariance	- 1
    }
}
